package com.hainatong.jcmvvmbase.mainhome.fragment.holiday;

import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.blankj.utilcode.util.SizeUtils;
import com.hainatong.jcmvvmbase.Constants;
import com.hainatong.jcmvvmbase.MvvmLazyFragment;
import com.hainatong.jcmvvmbase.R;
import com.hainatong.jcmvvmbase.databinding.FragmentRecyclerviewBinding;
import com.hainatong.jcmvvmbase.mainhome.ComFragmentActivity;
import com.hainatong.jcmvvmbase.mainhome.adapter.HolidayHistoryAdapter;
import com.hainatong.jcmvvmbase.mainhome.entity.SysMsgBean;
import com.hainatong.jcmvvmbase.widget.recycleviewdriver.ListItemDecoration;
import com.hainatong.mvvmbase.base.NoViewModel;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;

import java.util.ArrayList;
import java.util.List;

public class HolidayHistoryFragment extends MvvmLazyFragment<FragmentRecyclerviewBinding, NoViewModel>
{
    private HolidayHistoryAdapter adapter;
    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_recyclerview;
    }

    @Override
    public int getBindingVariable() {
        return 0;
    }

    @Override
    protected void onRetryBtnClick() {

    }

    @Override
    protected void initView(View view)
    {
        adapter = new HolidayHistoryAdapter();
        viewDataBinding.recyclerview.addItemDecoration(new ListItemDecoration(SizeUtils.dp2px(10)));
        viewDataBinding.recyclerview.setLayoutManager(new LinearLayoutManager(getContext()));
        viewDataBinding.recyclerview.setHasFixedSize(true);
        viewDataBinding.recyclerview.setAdapter( adapter );

        viewDataBinding.refreshlayout.setRefreshHeader( new ClassicsHeader(getActivity()));
        viewDataBinding.refreshlayout.setRefreshFooter( new ClassicsFooter(getActivity()));
        viewDataBinding.refreshlayout.setOnRefreshListener(refreshLayout -> {
            refreshLayout.finishRefresh(true);
        });
        viewDataBinding.refreshlayout.setOnLoadMoreListener(refreshLayout -> {
            refreshLayout.finishLoadMore(true);
        });

        adapter.setOnItemClickListener((adapter1, view1, position) -> {

            Bundle bundle = new Bundle();
            bundle.putString( Constants.FRAGMNET_TYPE, Constants.VIEW_HOLIDAY_APPLY_DETAIL);
            ComFragmentActivity.start( getActivity(),bundle );

        });

    }

    @Override
    protected void lazyLoad()
    {
        List<SysMsgBean> beanList = new ArrayList<>();
        SysMsgBean msg = new SysMsgBean();
        beanList.add( msg );
        beanList.add( msg );
        beanList.add( msg );
        beanList.add( msg );
        beanList.add( msg );
        beanList.add( msg );
        beanList.add( msg );
        beanList.add( msg );
        beanList.add( msg );
        adapter.setList(beanList);

    }
}
